package com.example.bootDemo.onetoone;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 发送者
 *
 * @author zys20
 */
@Component
public class MessageSender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public void send() {
        String context = "hello " + simpleDateFormat.format(new Date());
        System.out.println("Sender : " + context);
        this.amqpTemplate.convertAndSend("hello", context);
    }
}
